package treemap.bean;

import java.text.Collator;
import java.util.Locale;

public class Dog implements Comparable<Dog>{

    private String name;
    private Integer age;

    public Dog(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }



    //获取中文排序对象collator,    int compare(Object o1, Object o2) 比较此方法两个参数的顺序。
    private Collator collator= Collator.getInstance(Locale.CHINA);


    @Override
    public int compareTo(Dog o) {

        //年龄相等的情况下 按照名字中文拼音顺序排列
        int i = this.getAge() - o.getAge();
        if(i == 0){

            return collator.compare(this.getName(),o.getName());   //中文拼音排序

        }
        return i;
    }
}
